﻿-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
CREATE PROCEDURE [dbo].[A_GET_ClassificacaoByUser]
	@IDUtilizador AS INT
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;
    
    DECLARE @IDCampeonato AS INT
	SELECT @IDCampeonato = IDCampeonato FROM A_RegistoCampeonatos WHERE IDUtilizador = @IDUtilizador
	AND Activo = 'S'
    
	SELECT
	U.DisplayName,
	Jogos,
	Vitorias,
	Empates,
	Derrotas,
	GM,
	GS,
	(GM - GS) AS DifGolos,
	Pontos
	FROM A_Classificacao C
	INNER JOIN A_Utilizadores U
	ON C.IDUtilizador = U.IDUtilizador
	AND C.IDCampeonato = @IDCampeonato
	ORDER BY Pontos DESC
	
END